<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 17-4-13
 * Time: 21:50
 */

namespace frontend\widget;


use backend\models\Goods;
use yii\base\Widget;
use yii\helpers\Url;
use yii\helpers\VarDumper;

class HotsaleGoodsWiget extends Widget
{
    const NEWGOODS = 1;
    const HOTSALE = 2;
    const FINEGOODS = 4;
    const RECOMMEND =8;

    public $count=5;//最多显示的商品的数量 默认10 个

    public $status = 7; //1(1) 表示新品 10(2) 表示热卖 100(4) 表示精品 1000(8) 表示推荐

    public $headMsg = [
        1=>'新品上架',
        2=>'热卖商品',
        3=>'新品 热卖',
        4=>'精品商品',
        5=>'新品热卖',
        6=>'热卖精品',
        7=>'新品热卖精品',
        8=>'推荐精品',
        9=>'新品推荐',
        10=>'新品推荐',
        11=>'新品推荐',
        12=>'新品推荐',
        13=>'新品推荐',
        
    ];

    public function run()
    {
        return $this->getGoods();
    }

    public function getGoods(){

        //根据要求获取需要的商品的对象
        $Agoods = Goods::find()->where(['&','status',$this->status])->limit($this->count)->all();
        $htmlcode = '';
        foreach ($Agoods as $goods){
            // $imgSrc = \Yii::$app->params['imgUrl'].$goods['logo'];
            $imgSrc = $goods->logoUrl();
            $goods = $goods->toArray();
            $linkUrl = Url::to(['shop/goods','goods_id'=>$goods['id'],'goods_category_id'=>1]);
           $htmlcode .= <<<HTMLCODE
                    <li>
                        <dl>
                            <dt><a href="{$linkUrl}"><img src="{$imgSrc}" alt="" /></a></dt>
                            <dd><a href="{$linkUrl}">{$goods['name']}</a></dd>
                            <dd><span>售价：</span><strong> ￥{$goods['shop_price']}</strong></dd>
                        </dl>
                    </li>
HTMLCODE;

        }

        return $htmlcode;
        $headstats = $this->headMsg[$this->status];
        
        return  <<<HOT
<div class="hotgoods leftbar mt10">
            <h2><strong>热销排行榜</strong></h2>
            <div class="leftbar_wrap">
                <ul>
                {$htmlcode}
                </ul>
            </div>
        </div>
HOT;
        //var_dump($goods);exit;
    }

    public function getGoodsList(){


    }
}